package feishu

import "fmt"

type Feishu struct {
	accessToken string
}

func InitFeishu(accessToken string) *Feishu {
	return &Feishu{accessToken: accessToken}
}

// Send 发送飞书自定义机器人消息
func (f *Feishu) Send(msg *Message) error {
	u := sendURL + f.accessToken
	var resp ResponseMeta
	_, err := postJSON(u, msg, &resp)
	if err != nil {
		return err
	}
	if !resp.Succeed() {
		return fmt.Errorf("%w; %v", ErrRequest, resp)
	}
	return nil
}
